function firstUniqChar(s: string): number {
  let arr: string[] = s.split("");
  for (let i = 0; i < arr.length - 1; i++) {
    if (arr[i] != "" && arr.indexOf(arr[i], i + 1) === -1) {
      return i;
    } else {
      if (arr[i] !== "") {
        let temp = arr.indexOf(arr[i], i + 1);
        arr[temp] = "";
        while ((temp = arr.indexOf(arr[i], temp + 1)) !== -1) {
          arr[temp] = "";
        }
      }
    }
  }
  if (arr[arr.length - 1] != "") {
    return arr.length - 1;
  } else {
    return -1;
  }
}
console.log(firstUniqChar("leetcode"));
